<include file="Public::header" />
    <div>
        <php> if ($user && in_array(ACTION_NAME,array('infoset','photoupload','linkset'))){ </php>
        <a href="{:U('memcp/infoset')}" title="帐号设置">帐号设置</a> | <a href="{:U('memcp/photoUpload')}" title="头像设置">头像设置</a> | <a href="linkSet" title="链接管理">链接管理</a>
        <php> } </php>
    </div>
    <div class="main">
            <volist name="data" id="vo">
                <p>
                    <form action="javascript:void(0)" method="post">
                        <php>$curr[$vo['ltid']] = ' selected="selected"';</php>
                        <select name="ltid">
                            <volist name="link_type" id="value">
                                <option value="{$value.ltid}" {$curr[$value['ltid']]}><img src="__APP__/resources/image/linkico/{$value.ico}" />{$value.tname}</option>
                            </volist>
                        </select>
                        <input type="text" name="url" value="{$vo.url}" />
                        <input class="save" type="button" value="保存" onClick="linksave(this);"/>
                        <input type="button" value="删除" onClick="linkdel(this);"/>
                        <input type="hidden" name="lid" value="{$vo.lid}" /> 
                    </form>
                </p>
            </volist>
        
        <script type="text/javascript">
            function linksave(obj) {
                var err = new Array();
                err[1] = '非法';
                err[2] = '这链接能链到哪?';
                err[3] = '请选择正确的类型';
                err[4] = '填写正确的URL'; 
                $(obj).attr('disabled',true);
                $.post('{:U('memcp/linkUpdate')}',{
                    lid : $(obj).parents('form').find('input[name=lid]').val(),
                    url : $(obj).parents('form').find('input[name=url]').val(),
                    ltid : $(obj).parents('form').find('select').val(),
                    {:C('TOKEN_NAME')} : $(obj).parents('form').find('input[name={:C('TOKEN_NAME')}]').val(),
                 },
                 function(txt){
                            if(typeof(err[txt]) != 'undefined'){
                                alert(err[txt]);
                                $(obj).attr('disabled',false);
                            }else{
                                alert('修改成功');
                                $(obj).attr('disabled',false);
                                window.location.reload();
                            }
                 },'json' );         
            }

            function linkdel(obj) {
                var err = new Array();
                err[1] = '非法';
                $(obj).attr('disabled',true);
                $.post('{:U('memcp/linkdel')}',{
                    lid : $(obj).parents('form').find('input[name=lid]').val(),
                    {:C('TOKEN_NAME')} : $(obj).parents('form').find('input[name={:C('TOKEN_NAME')}]').val(),
                 },
                 function(txt){
                            if(typeof(err[txt]) != 'undefined'){
                                alert(err[txt]);
                                $(obj).attr('disabled',false);
                            }else{
                                alert('删除成功');
                                $(obj).attr('disabled',false);
                                window.location.reload();
                            }
                 },'json' );      
            }
        </script>

        <form action="{:U('memcp/linkadd')}" method="post">
            <select name="ltid">
                <volist name="link_type" id="value">
                    <option value="{$value.ltid}"><img src="__APP__/resources/image/linkico/{$value.ico}" />{$value.tname}</option>
                </volist>
            </select>
            <input type="text" name="url" value="" />
            <input type="submit" name="submit" value="新增" />
        </form>
    </div>
<include file="Public::footer" />